!function(e){
	
	//添加样式
	window.onload = function(){
		var style = document.createElement('style');
		style.type = 'text/css';
		style.innerHTML = `
			.dm-load{position:absolute;top:0;left:0;width:100%;height:100%;height:100%;z-index:9998}
			.dm-load .wrap{position:absolute;top:50%;left:50%;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%);background:rgba(0,0,0,.6);padding:20px 14px 14px;z-index:9999;border-radius:4px;}
			.dm-load .icon{width:32px;height:32px;position:relative;margin:auto;}
			.dm-load .icon[data-type='load']{animation:loadAni 1.2s linear infinite;}
			@keyframes loadAni{ from{ transform:rotate(0); } to{ transform:rotate(360deg); } }
			.dm-load .txt{font-size:12px;text-align:center;color:#fff;margin-top:12px;opacity:.8;min-width:60px}
			.dm-tip { line-height: 40px; height: 40px; position: fixed; top: 50%; left: 50%; -webkit-transform: translateX(-50%); -ms-transform: translateX(-50%); -moz-transform: translateX(-50%); -o-transform: translateX(-50%); transform: translateX(-50%); background: rgba(0, 0, 0, .6); padding: 0 24px; border-radius: 3px; color: #fff; font-size: 14px; z-index: 999; margin-top: 20px; opacity: 0; }
			.dm-selMod{width: 96%;position: absolute;z-index: 20;bottom: -100%;left: 2%;}
			.dm-selMod .cancel{display: block;text-align: center;border-radius: 4px;line-height: 44px;background-color: #fff;font-size: 14px;margin: 12px 0;}
			.dm-selMod ul{background-color: #fff;font-size: 14px;line-height: 44px;border-radius: 4px;overflow: hidden;text-align: center;}
			.dm-mask{width: 100%;height: 100%;z-index: 19;background-color: rgba(0,0,0,.5);position: absolute;top: 0;left: 0;}
			.dm-msg{width: 70%;background-color: #fff;border-radius: 6px;position: absolute;z-index: 20;top: 50%;left: 15%;-webkit-transform: translateY(-50%);transform: translateY(-50%);overflow: hidden;}
			.dm-msg .bt{font-size: 16px;padding-top: 20px;text-align: center;margin-bottom: -4px;}
			.dm-msg .txt{padding: 24px;line-height: 1.2;color: #333;text-align: center;}
			.dm-msg .txt input{width: 100%;height:40px;box-sizing: border-box;padding: 0 10px;border: 1px solid #ddd;font-size: 14px;line-height: 1.2;}
			.dm-msg .btn-box{background-color: #fafafa;line-height: 44px;text-align: center;color: #888;font-weight: bold;}
			.dm-msg .btn-box .enter{color: #51BBED;}
		`;
		document.head.appendChild(style);
	};
	
	//alert
	e.dmAlert = function(msg,option){
		var option = option == undefined ? option = {} :option = option ;
	
		option.type == undefined ? option.type = 0 : option.type;
		option.enter == undefined ? option.enter='确定' : option.enter;
		option.cancel == undefined ? option.cancel='取消' : option.cancel;
		
		$("body").append(`
			<div id="mask">
				<div class="dm-mask"></div>
				<div class="dm-msg">
					<h4 class="txt">${msg}</h4>
					<ul class="top-line h5 btn-box flex-row">
						${option.type != 1 ? `<li class="flex-full cancel">${option.cancel}</li>` : ''}
						<li class="flex-full left-line enter">${option.enter}</li>
					</ul>
				</div>
			</div>
		`);
		//关闭
		function closeMask(){
			$("#mask").hide(0,function(){
				$("#mask").remove();
			});
		};
		
		//取消
		$("#mask .dm-msg .cancel").click(function(){
			closeMask();
			if(typeof option.error == 'function'){
				option.error();
			};
		});
		
		//确定
		$("#mask .dm-msg .enter").click(function(){
			closeMask();
			if(typeof option.success == 'function'){
				option.success();
			};
		});
	};
	
	//tip弹窗
	e.tip = function(content, callback){
		new dm_tip(content, callback);
		function dm_tip(content, callback){
			this.content = content;
			this.tip = document.createElement('div');
			this.tip.className = 'dm-tip ani';
			this.tip.innerHTML = this.content;
			document.body.appendChild(this.tip);
			var that = this;
			setTimeout(function(){
				that.tip.style.marginTop = '-20px';
				that.tip.style.opacity = 1;
				setTimeout(function(){
					that.tip.style.opacity = 0;
					setTimeout(function(){
						that.tip.parentNode.removeChild(that.tip);
						typeof callback == 'function' ? callback() : '';
					},500);
				},1200);
			},10);
		};
	};
	
	//选择模组
	e.dmSelect = function(arr,callback){
		var list = '';
		for(i in arr){
			list += `<li class="top-line" data-index="${i}">${arr[i]}</li>`;
		};
		
		$("body").append(`
			<div id="dmSelectMod">
				<div class="dm-mask"></div>
				<div class="dm-selMod">
					<ul>${list}</ul>
					<a class="cancel">取消</a>
				</div>
			</div>
		`);
		
		$("#dmSelectMod .dm-selMod").animate({'bottom':0});
		
		//取消
		$("#dmSelectMod .cancel,#dmSelectMod .dm-mask").click(function(){
			$("#dmSelectMod .dm-mask").fadeOut();
			$("#dmSelectMod .dm-selMod").animate({'bottom':'-100%'},function(){
				$("#dmSelectMod").remove();
			});
		});
		
		//选择
		$("#dmSelectMod ul li").click(function(e){
			$("#dmSelectMod .dm-mask").fadeOut();
			$("#dmSelectMod .dm-selMod").animate({'bottom':'-100%'},function(){
				$("#dmSelectMod").remove();
			});
			
			var index = e.currentTarget.getAttribute('data-index');
			if(typeof callback == 'function'){
				callback(index);
			};
		});
	};
	
	//加载动画
	e.showModel = function(option){
		
		var option = option == undefined ? option = {} : option = option ;
		option.title == undefined ? option.title = '拼命加载中' : option.title;
		option.icon == undefined ? option.icon = 'load' : option.icon;//warn,success,load
		option.time == undefined ? option.time = 1500 : option.time ;
		
		if($('.dm-load').length == 0){
			$('body').append(`
				<div class="dm-load">
					<div class="wrap">
						<ul class="icon" data-type="${option.icon}">
							<img src="http://114.215.188.193:8080/icon/${option.icon}.png" />
						</ul>
						<p class="txt">${option.title}</p>
					</div>
				</div>
			`);
		};
		
		setTimeout(function(){
			$('.dm-load').hide(0,function(){
				$('.dm-load').remove();
				if(typeof option.success == 'function'){
					option.success();
				};
			});
		},option.time);
	};
	
}(window);